﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

#include "GmStructure.h"
#include "IExternalObject.h"
#include "GbmpQuickCast.h"
#include "DbDataSchema.h"
#include "NdbObjectSchematic.h"
#include "IElementDeletionComponent.h"

namespace gcmp
{
    class IDocument;
    class IGraphicsElementShape;
    class IBody;

    //Revit导入后生成的通用对象
    class GM_STRUCTURE_EXPORT RevitElement : public gcmp::NdbObjectSchematic, public gcmp::IExternalObject
    {
        DBOBJECT_DATA_BEGIN_AND_QUICK_CAST_FROM(gcmp, RevitElement, gcmp::NdbObjectSchematic, CD421EE5 - 3D5E - 4C3F - 867D - 0A9AFACBE243, gmstructure, gcmp::IExternalObject)
            DATA_TRANSIENT(IElement*, pOwnerElement)
        DBOBJECT_DATA_END

    public:
        static RevitElement* Create(gcmp::IDocument* pDoc);
        static const RevitElement* Get(const IDocument* pDoc, const ElementId& id);
        static RevitElement* GetFw(IDocument* pDoc, const ElementId& id);
        bool UpdateShape(const std::vector<std::wstring>& ggpStrArray);
        bool UpdateShape(OwnerPtr<IBody> opBody);

        ElementId GetOwnerElementId() const;
        IDocument* GetDocument() const;

#pragma region IExternalObject接口
    public:
        virtual bool SetOwnerElement(IElement* pOwnerElement) override;
        virtual IElement* GetOwnerElement() override { return m_pOwnerElement; }
        virtual const IElement* GetOwnerElement() const override { return m_pOwnerElement; }

        virtual NdbObject* GetTopOwnerObject() const override;
    public:
        virtual ~RevitElement() {}

#pragma region 关联更新
        virtual void UpdateForWeakParentDeletion(const std::set<ElementId>& deletedElementIds) override;

        virtual void ReportParents(IElementParentReporter& reporter) const override;

#pragma endregion 关联更新

#pragma region 其他
        virtual bool FinishEditing() override;
#pragma endregion 其他

#pragma endregion IExternalObject接口
    public:
        static Guid GetGuid() { return{ 0xcd421ee5, 0x3d5e, 0x4c3f,{ 0x86, 0x7d, 0x0a, 0x9a, 0xfa, 0xcb, 0xe2, 0x43 } }; }
    };

}
